<!DOCTYPE html>
<html lang="en" style="font-size: 20px;">
<head>
    <meta charset="UTF-8"/>
    <meta name="viewport" content="width=device-width, initial-scale=1.0"/>
    <meta http-equiv="X-UA-Compatible" content="ie=edge"/>
    <title>小说模式</title>
    <style>
        html,
        body {
            margin-left: 5px;
            margin-right: 5px;
            padding: 0;
            height: 100%;
        }

        iframe {
            width: 100%;
            opacity: 0;
            border: none;
        }

        h4 {
            font-size: 1rem;
        }

        .singlePage {
            font-size: 0.8rem;
            /* border-bottom: 4px solid #8b8b8d; */
            transition: all linear 0.4s;
        }

        .singlePage .singlePage-novel #BookText {
            padding: 0 20px;
            line-height: 1.4;
            font-size: 18px;
            color: #5d5d5d;
        }

        .singlePage h3 {
            line-height: 1.4;
            font-size: 18px;
            margin-top: 10px;
            padding: 0 20px;
            color: #333;
            display: none;
        }

        .singlePage h3:first-of-type {
            display: block;
        }

        .singlePage li,
        .singlePage dd,
        .singlePage p {
            margin-top: 0;
            margin-bottom: 0;
            padding: 10px 15px;
            list-style: none;
            border-bottom: 1px solid #ddd;
            margin-left: 0;
        }

        .singlePage li a,
        .singlePage dd a,
        .singlePage p a {
            font-size: 15px;
            color: #6d6d6d;
        }

        .authorAndDate {
            font-size: 0.7rem;
        }

        img {
            width: 100% !important;
        }

        a {
            text-decoration: none;
        }

        .day a,
        body a {
            /* color: #000 !important; */
        }

        .night a {
            color: #2a779d !important;
        }

        .day,
        body {
            background: #f2f2f2;
        }

        .night {
            background: #222224;
            color: #8b8b8d !important;
        }

        .endTxt {
            text-align: center;
            font-size: 0.7rem;
            color: #8b8b8d;
            margin: 0.8rem 0;
        }

        .adBox {
            height: 8rem;
            width: 100%;
            color: white;
        }



    </style>
</head>

<body>
<div id="novel" style="width: 100%;overflow: scroll">
    <iframe
            id="ramForSingleNovel"
            frameborder="0"
            style="position: fixed;left: -1000%;"
    ></iframe>
    <div id="novelContent">
    </div>
    <div
            id="loadMore"
            style="width: 100%;height: 60px;line-height: 60px;font-size: 14px;text-align: center;margin: 0;padding: 0;"
    >
        正在加载下一章
    </div>

</div>

<script>
    function findPosition(eleid) {

        // var img = document.getElementById(eleid);

        var views = document.getElementsByClassName(eleid);
        var img = views[views.length - 1]

        var left = img.getBoundingClientRect().left + img.scrollLeft;
        var top = img.getBoundingClientRect().top + img.scrollTop;
        var width = img.getBoundingClientRect().right - left;
        var height = img.getBoundingClientRect().bottom - top;
        window.FuTillIFu.getLocation(left, top, width, height)

    }


    function createSinglePage(ele) {
        // 创建单篇容器
        var div = document.createElement("div");
        div.className = "singlePage";
        div.style.opacity = "0";
        ele.appendChild(div);
        return div;
    }

    function shield(data) {
        // 屏蔽数据中的 Iframe, Script, Css, Style
        var iframeReg = /<iframe(.|\r|\n)*?>(.|\r|\n)*?<\/iframe>{1}/g;
        //var scriptReg = /<script(.|\r|\n)*?>(.|\r|\n)*?<\/script>{1}/g;
        var cssReg = /<link(.|\r|\n)*?>{1}/g;
        var styleReg = /<style(.|\r|\n)*?>(.|\r|\n)*?<\/style>{1}/g;
        var evalReg = /\"eval([^\"]*?)\"/g;
        // var aReg =/<a([\s]+|[\s]+[^<>]+[\s]+)href=(\"([^<>"\']*)\"|\'([^<>"\']*)\')[^<>]*>/g;
        // return data.replace(iframeReg, '').replace(scriptReg, '').replace(cssReg, '').replace(styleReg, '').replace(aReg, '');
        return data
            .replace(iframeReg, "")
            .replace(cssReg, "")
            .replace(styleReg, "")
            .replace(evalReg, "");
    }

    function getHost() {
        return FuTillIFu.getHost();
    }

    var novel = document.getElementById("novel");
    var content = document.getElementById("novelContent");
    var ram = document.getElementById("ramForSingleNovel");
    var loading = document.getElementById("loadMore");
    var title = document.getElementById("title");

    function setNovel(data) {
        var div = createSinglePage(content);
        // 插入小说内容
        var box = document.createElement("div");
        box.className = "singlePage-novel";
        box.innerHTML = data;
        content.appendChild(box);

        var endTxt = document.createElement("div");
        endTxt.innerHTML = "······本章完······";

        var adBox = document.createElement("div");

        adBox.innerHTML = "<img class=\"adBox\" onclick = \"findPosition('adBox')\"></img>";

        endTxt.className = "endTxt";
        box.appendChild(endTxt);
        box.appendChild(adBox);
        div.style.opacity = "1";

        //用于触发自动加载该广告的位置
        var views = document.getElementsByClassName("adBox");
        views[views.length - 1].click();

    }

    function setIndex(data) {
        // 插入目录
        var div = createSinglePage(content);
        div.innerHTML = data;
        div.style.opacity = "1";
    }

    function start(data) {
        // 启动
        var content = shield(data);
        var doc = ram.contentDocument || ram.document;
        doc.documentElement.innerHTML = content; // 缓存单篇小说内容
        //解析目录或内容
        if (FuTillIFu.isIndex()) {
            setIndex(data);
        } else setNovel(data);
    }

    function setFontSize(num) {
        // 设置字体大小
        document.getElementsByTagName("html")[0].style.fontSize =
            num * 20 + "px";
    }

    function modeToggle(mode) {
        // 切换夜间/正常模式
        var body = document.body || document.documentElement;
        if (mode == "night") {
            body.className = "night";
        } else if (mode == "day") {
            body.className = "day";
        }
    }

    function loadErr() {
        // 重试加载
        function loadHandler() {
            loading.innerText = "正在加载...";
            FuTillIFu.onLoadMore();
            loading.removeEventListener("click", loadHandler, false);
        }

        loading.innerText = "加载失败, 点击重试";
        loading.addEventListener("click", loadHandler, false);
    }

    //文档高度
    function getDocumentTop() {
        var scrollTop = 0,
            bodyScrollTop = 0,
            documentScrollTop = 0;
        if (document.body) {
            bodyScrollTop = document.body.scrollTop;
        }
        if (document.documentElement) {
            documentScrollTop = document.documentElement.scrollTop;
        }
        scrollTop =
            bodyScrollTop - documentScrollTop > 0
                ? bodyScrollTop
                : documentScrollTop;
        return scrollTop;
    }
    //可视窗口高度
    function getWindowHeight() {
        var windowHeight = 0;
        if (document.compatMode == "CSS1Compat") {
            windowHeight = document.documentElement.clientHeight;
        } else {
            windowHeight = document.body.clientHeight;
        }
        return windowHeight;
    }
    //滚动条滚动高度
    function getScrollHeight() {
        var scrollHeight = 0,
            bodyScrollHeight = 0,
            documentScrollHeight = 0;
        if (document.body) {
            bodyScrollHeight = document.body.scrollHeight;
        }
        if (document.documentElement) {
            documentScrollHeight = document.documentElement.scrollHeight;
        }
        scrollHeight =
            bodyScrollHeight - documentScrollHeight > 0
                ? bodyScrollHeight
                : documentScrollHeight;
        return scrollHeight;
    }

    var isLoading = false;

    function loaded() {
        isLoading = false;
    }

    function refresh() {
        // 目錄內容切換
        window.removeEventListener("scroll", scrollHandler, false);
        document.body.scrollTop = 0;
        novel.style.opacity = "0";
        content.innerHTML = "";
        novel.style.opacity = "1";
    }

    function scrollHandler() {
        var bottomMargin = FuTillIFu.isIndex() == true ? 50 : 1000;
        if (getScrollHeight() - getWindowHeight() - getDocumentTop() < bottomMargin) {
            if (!isLoading) {
                FuTillIFu.onLoadMore();
                isLoading = true;
            }
        }
        if (getScrollHeight() - getWindowHeight() - getDocumentTop() < 1) {
            FuTillIFu.adVisible();
        }
    }

    function action() {
        start(FuTillIFu.getDom());
        window.addEventListener("scroll", scrollHandler, false);
    }



</script>
</body>
</html>
